//
//  HDRecognizeeMeVC.swift
//  HuaDaoPeifu
//
//  Created by ZERO on 2018/6/7.
//  Copyright © 2018年 paiyipai. All rights reserved.
//

import UIKit

class HDRecognizeeMeVC: UIViewController {
    
    @IBOutlet weak var scrollView: UIScrollView!
    @IBOutlet weak var scrollLength: NSLayoutConstraint!
    
    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var genderLabel: UILabel!
    @IBOutlet weak var relationLabel: UILabel!
    @IBOutlet weak var IDnumberLabel: UILabel!
    
    @IBOutlet weak var phoneTF: UITextField!
    @IBOutlet weak var professionTF: UITextField!
    @IBOutlet weak var addressTF: UITextField!
    @IBOutlet weak var mailTF: UITextField!
    
    @IBOutlet weak var accountNameTF: UITextField!
    @IBOutlet weak var bankNumberTF: UITextField!
    @IBOutlet weak var bankNameTF: UITextField!
    
    @IBOutlet weak var branchLabel: UILabel!
    
    @IBOutlet weak var positiveImgView: UIImageView!
    @IBOutlet weak var reverseImgView: UIImageView!
    
    
    let systemPhoto = PYPSystemCameraPhotoControl()
    var positiveImage = UIImage()
    var reverseImage = UIImage()
    var imgtype = Int()

    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "修改被保人(本人)信息"
        setUI()

        // Do any additional setup after loading the view.
    }
    func setUI() {
        
        scrollView.contentSize = CGSize(width: 0, height: 760)

    }
    
    
    // 正面上传
    @IBAction func positive(_ sender: UIButton) {
        imgtype = 0
        systemPhoto.editAvatar(self as PYPSystemCameraPhotoControlDelegate)

    }
    
    // 反面上传
    @IBAction func reverse(_ sender: UIButton) {
        imgtype = 1
        systemPhoto.editAvatar(self as PYPSystemCameraPhotoControlDelegate)
    }
    // 修改完成
    @IBAction func completeAction(_ sender: UIButton) {
        
    }
//    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
//        self.view.endEditing(true)
//    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
extension HDRecognizeeMeVC: PYPSystemCameraPhotoControlDelegate {
    func didFinishPickingMediaWithInfo(_ info: [String : AnyObject]) {
        let image = info[UIImagePickerControllerEditedImage] as? UIImage
        
        if imgtype == 0{
            positiveImage = image!
            positiveImgView.image = image!
        }else{
            reverseImage = image!
            reverseImgView.image = image!
        }
        
        print(HDAccountHandler.token)
//        HDApiManagerHandler.requestUploadUserHeadImg(HDAccountHandler.token!, headimg: image!, success: { (dict) in
//
//            let status : Int? = dict.object(forKey: "status") as? Int
//
//            if status == 1 {
//                HDAccountHandler.saveUserHeadImage(image!)
//            }
//
//        }) { (error) in
//
//        }
    }
}
